package com.ruoyi.web.controller.flyflow;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.controller.flyflow.factory.FlyFlowFactory;
import com.ruoyi.web.controller.flyflow.factory.FlyFlowFnFactory;
import com.ruoyi.web.controller.flyflow.vo.FlyFlowTaskListVO;
import com.ruoyi.web.controller.flyflow.vo.FlyFloyCompleteTaskVO;
import com.ruoyi.web.controller.flyflow.vo.FlyFloyFormatStartNodeShowVO;
import com.ruoyi.web.controller.flyflow.vo.FlyFloyQueryHeaderShowVO;
import com.ruoyi.web.core.JoR;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 工作流请求处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/joflyflow")
public class JoFlyFlowController
{
    private static final Logger log = LoggerFactory.getLogger(JoFlyFlowController.class);

    @Resource
    private FlyFlowFactory flyFlowFactory;
    @Resource
    private FlyFlowFnFactory fnFactory;

    /**
     * 获取当前节点
     */
    @GetMapping("/findByProcInstId")
    public JSONObject findByProcInstId(FlyFlowTaskListVO flyFlowTaskListVO)
    {
        return flyFlowFactory.findByProcInstId(flyFlowTaskListVO.getProcessId());
    }

    /**
     * 获取流程详情
     */
    @GetMapping("/getByProcessInstanceId")
    public AjaxResult getByProcessInstanceId(FlyFlowTaskListVO flyFlowTaskListVO)
    {
        return JoR.success(fnFactory.getProcessInstanceRecordVO(flyFlowTaskListVO.getProcessId()));
    }

    /**
     * 待办列表
     */
    @PostMapping("/combination/group/queryTodoTaskList")
    public JSONObject queryTodoTaskList(@RequestBody FlyFlowTaskListVO flyFlowTaskListVO)
    {
        return flyFlowFactory.queryTodoTaskList(flyFlowTaskListVO);
    }

    /**
     * 待办环节信息
     */
    @GetMapping("/task/getTask/{taskId}")
    public JSONObject getTask(@PathVariable String taskId)
    {
        return flyFlowFactory.getTask(taskId);
    }

    /**
     * 待办流程头部信息
     */
    @PostMapping("/base/queryHeaderShow")
    public JSONObject queryHeaderShow(@RequestBody FlyFloyQueryHeaderShowVO flyFloyQueryHeaderShowVO)
    {
        return flyFlowFactory.queryHeaderShow(flyFloyQueryHeaderShowVO);
    }

    /**
     * 待办流程表单信息
     */
    @PostMapping("/form/getFormDetail")
    public JSONObject getFormDetail(@RequestBody FlyFloyQueryHeaderShowVO flyFloyQueryHeaderShowVO)
    {
        return flyFlowFactory.getFormDetail(flyFloyQueryHeaderShowVO);
    }

    /**
     * 查询任务操作数据
     */
    @GetMapping("/base/queryTaskOperData")
    public JSONObject queryTaskOperData(String taskId)
    {
        return flyFlowFactory.queryTaskOperData(taskId);
    }

    /**
     * 格式化开始节点显示
     */
    @PostMapping("/base/formatStartNodeShow")
    public JSONObject formatStartNodeShow(@RequestBody FlyFloyFormatStartNodeShowVO flyFloyFormatStartNodeShowVO)
    {
        return flyFlowFactory.formatStartNodeShow(flyFloyFormatStartNodeShowVO);
    }

    /**
     * 流程待办环节
     */
    @PostMapping("/base/nextNode")
    public JSONObject nextNode(@RequestBody FlyFloyFormatStartNodeShowVO flyFloyFormatStartNodeShowVO)
    {
        return new JSONObject().fluentPut("nextNode", flyFlowFactory.nextNode(flyFloyFormatStartNodeShowVO));
    }

    /**
     * 完成任务
     */
    @PostMapping("/task/completeTask")
    public JSONObject completeTask(@RequestBody FlyFloyCompleteTaskVO flyFloyCompleteTaskVO)
    {
        return flyFlowFactory.completeTask(flyFloyCompleteTaskVO);
    }

    /**
     * 完成任务
     */
    @PostMapping("/refreshToken")
    public JSONObject refreshToken()
    {
        return flyFlowFactory.refreshToken();
    }

    /**
     * 刷新节点
     */
    @GetMapping("/refreshNodes")
    public JSONObject refreshNodes(String key,String value)
    {
        return flyFlowFactory.refreshNodes(key,value);
    }

}
